/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p>Project: javaweb - Upload
 * <p>Powered by webrx On 2022-03-11 11:32:25
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Uploadf extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Part file = null;
        String n = "";
        try{
            n = req.getParameter("user");
            file = req.getPart("fs");
        }catch(Exception e){
            n = "上传失败，不能超出10kb";
        }

        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<meta charset=\"utf-8\">");
        out.println("<title>玉灵 QQ:7031633 Email:webrx@126.com</title>");
        out.println("<meta name=\"keywords\" content=\"关键字\">");
        out.println("<meta name=\"description\" content=\"简介\">");
        out.println("</head>");
        out.println("<body>");

        out.printf("<h3>%s</h3>",n);
        if(!n.contains("失败")) {
            out.printf("<h3>%s</h3>", file.getName());
            out.printf("<h3>%s</h3>", file.getSubmittedFileName());
            out.printf("<h3>%s</h3>", file.getSize());
            out.printf("<h3>%s</h3>", file.getContentType());
        }
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
